// DialogAddDevice.cpp : implementation file
//

#include "stdafx.h"
#include "DesktopClient.h"
#include "DialogAddDevice.h"
#include "afxdialogex.h"
#include "CameraWindow.h"

// CDialogAddDevice dialog

IMPLEMENT_DYNAMIC(CDialogAddDevice, CDialogEx)

CDialogAddDevice::CDialogAddDevice(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDialogAddDevice::IDD, pParent)
	, m_chkCamAuth(FALSE)
{
	m_nAddDeviceType = ADD_WEB_CAM;
}

CDialogAddDevice::~CDialogAddDevice()
{
}

void CDialogAddDevice::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_CMB_DEVICE_CATE, m_cmbDeviceCategory);
	DDX_Control(pDX, IDC_EDT_CAM_NAME, m_edtCamName);
	DDX_Control(pDX, IDC_EDT_CAM_ADDRESS, m_edtCamAddress);
	DDX_Control(pDX, IDC_EDT_CAM_PORT, m_edtCamPort);
	DDX_Control(pDX, IDC_CMB_CAM_CODEC, m_cmbCamCodecs);
	DDX_Control(pDX, IDC_EDT_CAM_USER, m_edtCamUsername);
	DDX_Check(pDX, IDC_CHK_CAM_AUTH, m_chkCamAuth);
	DDX_Control(pDX, IDC_EDT_CAM_PASSWORD, m_edtCamPwd);
	DDX_Control(pDX, IDC_EDT_CAM_URL, m_edtCamURL);
}


BEGIN_MESSAGE_MAP(CDialogAddDevice, CDialogEx)
	ON_BN_CLICKED(IDC_BTN_ADD_DEVICE, &CDialogAddDevice::OnBnClickedBtnAddDevice)
	ON_BN_CLICKED(IDCANCEL, &CDialogAddDevice::OnBnClickedCancel)
	ON_CBN_SELCHANGE(IDC_CMB_DEVICE_CATE, &CDialogAddDevice::OnCbnSelchangeCmbDeviceCate)
END_MESSAGE_MAP()


// CDialogAddDevice message handlers

void CDialogAddDevice::OnBnClickedBtnAddDevice()
{
	switch (m_nAddDeviceType)
	{
		case ADD_WEB_CAM:
			break;
		case ADD_IP_CAM:
			ValidateForIpCam();
			break;
		case ADD_VIDEO_SRC:
			break;
		default :
			break;
	}
	CDialogEx::OnOK();
}


void CDialogAddDevice::OnBnClickedCancel()
{	
	CDialogEx::OnCancel();
}


BOOL CDialogAddDevice::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_cmbDeviceCategory.SetCurSel(m_nAddDeviceType);
	ShowControlsByType(m_nAddDeviceType);

	return TRUE;  // return TRUE unless you set the focus to a control
}


void CDialogAddDevice::OnCbnSelchangeCmbDeviceCate()
{
	int nIndex = m_cmbDeviceCategory.GetCurSel();
	ShowControlsByType(nIndex);
	m_nAddDeviceType = nIndex;
}

void CDialogAddDevice::ShowControlsByType(int nType)
{
	switch (nType)
	{
	case ADD_WEB_CAM:
		ShowControlsForIPCam(FALSE);
		ShowControlsForVideoSrc(FALSE);
		ShowControlsForWebCam(TRUE);
		break;
	case ADD_IP_CAM:		
		ShowControlsForVideoSrc(FALSE);
		ShowControlsForWebCam(FALSE);
		ShowControlsForIPCam(TRUE);
		break;
	case ADD_VIDEO_SRC:		
		ShowControlsForWebCam(FALSE);
		ShowControlsForIPCam(FALSE);
		ShowControlsForVideoSrc(TRUE);
		break;
	default:
		break;
	}
}

void CDialogAddDevice::ShowControlsForIPCam(BOOL bShow)
{
	GetDlgItem(IDC_GROUP_CAMERA)->ShowWindow(bShow);
	GetDlgItem(IDC_ST_CAMERA_NAME)->ShowWindow(bShow);
	m_edtCamName.ShowWindow(bShow);
	GetDlgItem(IDC_ST_CAM_ADDRESS)->ShowWindow(bShow);
	m_edtCamAddress.ShowWindow(bShow);
	GetDlgItem(IDC_ST_CAM_PORT)->ShowWindow(bShow);
	m_edtCamPort.ShowWindow(bShow);
	GetDlgItem(IDC_ST_CAM_VIDEOCODEC)->ShowWindow(bShow);
	m_cmbCamCodecs.ShowWindow(bShow);
	GetDlgItem(IDC_CHK_CAM_AUTH)->ShowWindow(bShow);
	GetDlgItem(IDC_ST_CAM_USER)->ShowWindow(bShow);
	m_edtCamUsername.ShowWindow(bShow);
	GetDlgItem(IDC_ST_CAM_PASS)->ShowWindow(bShow);
	m_edtCamPwd.ShowWindow(bShow);
	GetDlgItem(IDC_ST_CAM_URL)->ShowWindow(bShow);
	m_edtCamURL.ShowWindow(bShow);
}

void CDialogAddDevice::ShowControlsForWebCam(BOOL bShow)
{

}

void CDialogAddDevice::ShowControlsForVideoSrc(BOOL bShow)
{

}

void CDialogAddDevice::ValidateForIpCam()
{
	CString strTmp;
	m_edtCamName.GetWindowTextW(strTmp);
	wsprintf(pCameraInfo->wchCameraName, strTmp.GetBuffer());

}

void CDialogAddDevice::ValidateForWebCam()
{

}

void CDialogAddDevice::ValidateForVideoSrc()
{

}